package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.QrtzSchedulerState;
import io.mybatis.example.springboot.service.QrtzSchedulerStateService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * QRTZ_SCHEDULER_STATE - 调度器状态表
 *
 * @author mkj
 */
@RestController
@RequestMapping("qrtzSchedulerStates")
public class QrtzSchedulerStateController {

  @Autowired
  private QrtzSchedulerStateService qrtzSchedulerStateService;

  @PostMapping
  public DataResponse<QrtzSchedulerStateDO> save(@RequestBody QrtzSchedulerStateDO qrtzSchedulerState) {
    return DataResponse.ok(qrtzSchedulerStateService.save( qrtzSchedulerState));
  }

  @GetMapping
  public RowsResponse<QrtzSchedulerStateDO> findList(@RequestBody QrtzSchedulerStateDO qrtzSchedulerState) {
    return RowsResponse.ok(qrtzSchedulerStateService.findList( qrtzSchedulerState));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<QrtzSchedulerStateDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzSchedulerStateService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<QrtzSchedulerStateDO> update(@PathVariable("id") Long id, @RequestBody QrtzSchedulerStateDO qrtzSchedulerState) {
    qrtzSchedulerState.setId(id);
    return DataResponse.ok(qrtzSchedulerStateService.update( qrtzSchedulerState));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzSchedulerStateService.deleteById(id) == 1);
  }

}
